cap log close
snapshot erase _all
clear all
estimates drop _all

*===========================*
*	Set Globals				*
*===========================*

	global filenum 30
	global filename "paper_figures"

*===========================*
*	Set Locals				*
*===========================*
		
	local outcomes 		"absent_paid"
	
*===========================*
*	Load In Analysis File	*
*===========================*
	log using "${log_path}/${filenum}_${filename}.smcl", replace
	
	use "${data_path}/analysis_file.dta" , clear
		
	gen covid_high = cdc_levels>=3 if month>=3
	replace covid_high = 0 if inrange(month,1,2) & asec_year==2020

snapshot save

*=======================================================*
*	Fig 2a: Paid Leave Taking and Tramsinssion Rates		*
*=======================================================*
snapshot restore 1
	collapse absent_paid rw_cases_per100k [pw=wtfinl], by(month asec_year)
	
	** Need to generate event time to reorder December to come before January 
		gen emonth = month-3 if inrange(month,1,6)
			replace emonth = -3 if month==12
			
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
		
	replace rw_cases_per100k = 0 if emonth<0
	
	sort emonth asec_year
	
	#delimit ;
	twoway 	
			connected absent_paid emonth if asec_year==2020, yaxis(1) lcolor(black) mcolor(black) msize(medium)||
			connected absent_paid emonth if asec_year==2019, yaxis(1) lcolor(gs10) lpattern(dash) mcolor(gs10) msymbol(D) msize(medium) ||
			connected absent_paid emonth if asec_year==2018, yaxis(1) lcolor(gs10) lpattern("..-") mcolor(gs10) msymbol(T) msize(medium)||
			connected rw_cases_per100k emonth if asec_year==2020, yaxis(2) lcolor(red) mcolor(red) 	 msize(medium)		
			ytitle("Share Absent with Pay", axis(1) size(medlarg))
			ytitle("Avg Cases per 100k", axis(2) size(medlarg))			
			ylabel(0(0.01)0.03,axis(1) labsize(medlarge))
			ylabel(0(50)200, axis(2) labsize(medlarge))
			xlabel(-3(1)3,valuelabel labsize(medlarge))
			xtitle("")
			legend(	label(1 "Absences 2020") 
					label(2 "Absences 2019")
					label(3 "Absences 2018")
					label(4 "COVID Transmission")
					pos(6) row(1) order( 1 2 3 4)
					size(medium)
				  );
	#delimit cr

	graph export "${out_path}/${filenum}_absent_paid_w_cases.png", replace	




*===================================*
*	Fig 2b:  Tramsinssion Rates		*
*===================================*
snapshot restore 1
	keep if asec_year==2020
	collapse rw_cases_per100k [pw=wtfinl], by(month cdc_levels_m4)
	
	** Need to generate event time to reorder December to come before January 
		gen emonth = month-3 if inrange(month,1,6)
			replace emonth = -3 if month==12
			
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
		
	replace rw_cases_per100k = 0 if emonth<0
	
	sort emonth cdc_levels
	
	#delimit ;
	twoway 	connected rw_cases_per100k emonth if cdc_levels==1, lcolor(eltblue) mcolor(eltblue) msize(medium) ||	
			connected rw_cases_per100k emonth if cdc_levels==2, lcolor(midblue) mcolor(midblue) msize(medium)||
			connected rw_cases_per100k emonth if cdc_levels==3, lcolor(ebblue) mcolor(ebblue) msize(medium)||
			connected rw_cases_per100k emonth if cdc_levels==4, lcolor(navy) mcolor(navy) msize(medium)
			ytitle("Avg Cases per 100k", size(medium))			
			ylabel(0(50)250, labsize(medium))
			xlabel(-3(1)3,valuelabel labsize(medium) )
			xtitle("")
			legend( label(1 "Aprl Low") label(2 "Apr Moderate") 
					label(3 "Apr Substantial") label(4 "Apr High")
					order (4 3 2 1) size(medium))
			yline(10, lpattern(solid) lcolor(gs10%50))
			yline(50, lpattern(solid) lcolor(gs10%50))
			yline(100, lpattern(solid) lcolor(gs10%50))			
			text(5 -2.75 "Low", size(small))
			text(25 -2.75 "Moderate",  size(small))
			text(75 -2.75 "Substantial",  size(small))
			text(150 -2.75 "High", size(small))
			;
	#delimit cr

	graph export "${out_path}/${filenum}_transmission.png", replace	
	
	
*===================================================*
*	Fig 4/3: Paid Leave Taking by Firm Size	(Means)	*
*===================================================*

forvalues t = 0/1{
	if `t' == 1		local ylabel "0(0.01)0.06"
	if `t' == 0		local ylabel "0(0.01)0.03"	
	
	forvalues s=0/1{
		snapshot restore 1

		keep if tw_binary_10ly==`t'
		keep if small==`s'
		
		collapse absent_paid  [pw=wtfinl], by(month y2020)
		
		gen emonth = month-3 if inrange(month,1,6)
			replace emonth = -3 if month==12
			
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
		
		sort emonth y2020
		#delimit ;
		twoway 	connected absent_paid emonth if y2020==1, lcolor(black) mcolor(black) msize(medium)||
				connected absent_paid emonth if y2020==0, lcolor(gs10)  mcolor(gs10)  msize(medium)
				ytitle("Share Absent with Pay", size(large))		
				ylabel("`ylabel'", labsize(medlarge))
				xlabel(-3(1)3,valuelabel  labsize(large))
				xtitle("Month", size(large))
				legend(	label(1 "2020") 
						label(2 "2018--2019")
						pos(6) col(2) row(1) size(medlarge)
					  );
		#delimit cr
		
		graph export "${out_path}/${filenum}_absent_paid_TW`t'_small`s'.png", replace	
	}	// end small large loop
} // end telework loop

*===================================================*
*	Fig 4/3: Paid Leave Taking by Firm Size	(Coefs)	*
*===================================================*
	
forvalues t = 0/1{

	** Read in Regression Results
		use "${out_path}/10_absent_paid.dta", clear
	
		** Select Sample
			keep if spec == "Dynamic DD" & sample=="TW`t'" & controls == "YES"
		
		** Generate Event Time
			gen emonth = .
				replace emonth = -3 if var=="m12_x_small_y2020"
				replace emonth = -2 if var=="m1_x_small_y2020"
				replace emonth = 0 if var=="m3_x_small_y2020"
				replace emonth = 1 if var=="m4_x_small_y2020"
				replace emonth = 2 if var=="m5_x_small_y2020"
				replace emonth = 3 if var=="m6_x_small_y2020"
				
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
	
		** Setup rspike variables
				
			gen beta = coef/mu * 100
			gen hi = (coef/mu + 1.96 * stderr/mu) * 100
			gen lo = (coef/mu - 1.96 * stderr/mu) * 100

		** Add Feb Data Point
			insobs 1
			replace emonth=-1 if emonth==.
			replace beta=0 if emonth==-1
			replace lo=0 if emonth==-1
		
		sort emonth 

		#delimit ;
			 twoway (rspike hi lo emonth, lcolor(black) lwidth(medthick) ) ||
			 (scatter beta emonth, mcolor(black) msize(medium) ) ,
			 legend(off)
				yline(0, lcolor(gs12))
				ytitle("FFCRA-Induced Change in Paid Leave Taking", size(medlarge))
				xtitle("")
				graphregion(color(white)) bgcolor(white)
				xlabel(-3(1)3,valuelabel labsize(medlarge) )
				ylabel(, labsize(medlarge))
				;
		#delimit cr
				
		graph export "${out_path}/${filenum}_DDD_absent_paid_TW`t'.png", replace	
	} // end telework loop


	
*===============================================*
*	Fig 5: Subsample Figures (CDC Levels)		*
*===============================================*
	
	snapshot restore 1

	** Read in Regression Results

		local subsample "cdc_levels"
		
		use "${out_path}/11_absent_paid_cdc_levels_m4_TW0.dta", clear
	
		** Select Sample
			keep if controls == "YES"
			
		
		** Generate Event Time
		local jigger = 0
		gen emonth = .
		foreach s in 1 4{
			
			if `s'>1 local jigger = `jigger' + 0.1
			
			replace emonth = -3 + `jigger' if var=="m12_x_small_y2020" 		& `subsample'==`s'
			replace emonth = -2 + `jigger' if var=="m1_x_small_y2020" 		& `subsample'==`s'
			replace emonth = 0 + `jigger'  if var=="m3_x_small_y2020" 		& `subsample'==`s'
			replace emonth = 1 + `jigger'  if var=="m4_x_small_y2020" 		& `subsample'==`s'
			replace emonth = 2 + `jigger'  if var=="m5_x_small_y2020" 		& `subsample'==`s'
			replace emonth = 3 + `jigger'  if var=="m6_x_small_y2020"		& `subsample'==`s'
		}
				
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
		
		** Setup rspike variables
				
			gen beta = coef
			gen hi = (coef + 1.96 * stderr) 
			gen lo = (coef - 1.96 * stderr) 

		** Add Feb Data Point
			insobs 1
			replace emonth=-1 	if emonth==. 
			replace beta=0 		if emonth==-1
			replace lo=0 		if emonth==-1
		
		sort emonth 		
		
		#delimit ;
			 twoway (rspike hi lo emonth if `subsample'==1, lcolor(gs10)) ||
					(rspike hi lo emonth if `subsample'==4, lcolor(black)) ||
					(scatter beta emonth if `subsample'==1, mcolor(gs10) msymbol(T)) ||
					(scatter beta emonth if `subsample'==4, mcolor(black) msymbol(D)) ||
					(scatter beta emonth if `subsample'==., mcolor(black) ), 
			 legend(label(3 "Apr Low") label(4 "Apr High") order(3 4) pos(6) row(1) size(medlarge))
				yline(0, lcolor(gs12))
				ytitle("FFCRA-Induced Change in Paid Leave Taking", size(med))
				xtitle("")
				graphregion(color(white)) bgcolor(white)
				xlabel(-3(1)3,valuelabel labsize(medlarge) )
				;
		#delimit cr
		
				
		graph export "${out_path}/${filenum}_DDD_absent_paid_apr_cdc_levels.png", replace	

		
	
*=======================================================*
*	Fig 6: Subsample Figures Apr Hi Gender Parent		*
*=======================================================*
	
	snapshot restore 1

	** Read in Regression Results

		local subsample "gender_parent"
		
		use "${out_path}/12_absent_paid_cdc_high_`subsample'_TW0", clear

		** Select Sample
			keep if controls == "YES"
			keep if s1== "cdc_high 1"
			
		** Setup Subsample
			gen subsample =.
		
		** Generate Event Time
		local jigger = 0
		gen emonth = .
		forvalues s=1/4{
			replace subsample = `s' 		if s2=="`subsample' `s'"
			
			if `s'>1 local jigger = `jigger' + 0.1
			
			replace emonth = -3 + `jigger' if var=="m12_x_small_y2020" 		& s2=="`subsample' `s'"
			replace emonth = -2 + `jigger' if var=="m1_x_small_y2020" 		& s2=="`subsample' `s'"
			replace emonth = 0 + `jigger'  if var=="m3_x_small_y2020" 		& s2=="`subsample' `s'"
			replace emonth = 1 + `jigger'  if var=="m4_x_small_y2020" 		& s2=="`subsample' `s'"
			replace emonth = 2 + `jigger'  if var=="m5_x_small_y2020" 		& s2=="`subsample' `s'"
			replace emonth = 3 + `jigger'  if var=="m6_x_small_y2020"		& s2=="`subsample' `s'"
		}
				
			label define month_lab -3 "Dec" -2 "Jan" -1 "Feb" 0 "Mar" 1 "Apr" 2 "May" 3 "Jun"
			label values emonth month_lab	
		
		** Setup rspike variables
			
			gen beta = coef
			gen hi = (coef + 1.96 * stderr) 
			gen lo = (coef - 1.96 * stderr) 
			
		** Add Feb Data Point
			insobs 1
			replace emonth=-1 	if emonth==. 
			replace beta=0 		if emonth==-1
			replace lo=0 		if emonth==-1
		
		sort emonth 

		
		#delimit ;
			 twoway (rspike hi lo emonth if subsample==1, lcolor(black)) ||
					(rspike hi lo emonth if subsample==2, lcolor(gs12) ) ||
					(scatter beta emonth if subsample==1, mcolor(black) msymbol(T)) ||
					(scatter beta emonth if subsample==2, mcolor(gs12) msymbol(T)) ||
					(scatter beta emonth if subsample==., mcolor(black) ), 
			 legend(label(3 "Women") label(4 "Men") order(3 4) pos(6) row(1) size(medlarge))
				yline(0, lcolor(gs12) lpattern(solid))
				ytitle("FFCRA-Induced Change in Paid Leave Taking", size(med))
				xtitle("")
				ylabel(-0.15(0.1)0.3)
				graphregion(color(white)) bgcolor(white)
				xlabel(-3(1)3,valuelabel labsize(medlarge) )
				;
		#delimit cr
		
		graph export "${out_path}/${filenum}_DDD_absent_paid_apr_hi_kids.png", replace	
		

	#delimit ;
			 twoway (rspike hi lo emonth if subsample==3, lcolor(black)) ||
					(rspike hi lo emonth if subsample==4, lcolor(gs12) ) ||
					(scatter beta emonth if subsample==3, mcolor(black) msymbol(T)) ||
					(scatter beta emonth if subsample==4, mcolor(gs12) msymbol(T)) ||
					(scatter beta emonth if subsample==., mcolor(black) ), 
			 legend(label(3 "Women") label(4 "Men") order(3 4) pos(6) row(1) size(medlarge))
				yline(0, lcolor(gs12) lpattern(solid))
				ytitle("FFCRA-Induced Change in Paid Leave Taking", size(med))
				xtitle("")
				ylabel(-0.15(0.1)0.3)
				graphregion(color(white)) bgcolor(white)
				xlabel(-3(1)3,valuelabel labsize(medlarge) )
				;
		#delimit cr
		
		graph export "${out_path}/${filenum}_DDD_absent_paid_apr_hi_nokids.png", replace	
		

				

log close
